﻿using DAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace ShopBack.Web.Controllers
{
    public class LoginController : Controller
    {
        // GET: Login
        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 登录页面
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult Login()
        {
            return View();
        }
        /// <summary>
        /// 判断登录是否成功
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Login(string userName, string pwd)
        {
            string Md5Pwd = MD5Jm.Md5jm(pwd);
            User user = UserService.GetUser(userName);
            if (user != null)
            {
                if (user.Pwd == Md5Pwd)
                {
                    FormsAuthentication.SetAuthCookie(userName, true);
                    //return Redirect("/Back/Home/Index");
                    return Json(new { Success = true, Message = "登录成功" });
                }
                else
                {
                    return Json(new { Success = false, Message = "密码错误" });
                }

            }
            else
            {
                return Json(new { Success = false, Message = "用户名不存在" });
            }

        }
        /// <summary>
        /// 注销用户登录
        /// </summary>
        /// <returns></returns>
        public ActionResult TuiLogin()
        {
            FormsAuthentication.SignOut();//注销
            return Redirect("/Login/Login");
        }
    }
}